﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;

namespace AdminForm
{
    public partial class Form1 : Form
    {
        ArrayList list = new ArrayList();

        class Hotel
        {
            public Hotel(String city, String name, int r, double m)
            {
                
                City = city; HotelName = name;
                Rooms = r; Rate = m;
            }
            public String City, HotelName;
            public int Rooms;
            public double Rate;
        }

        public Form1()
        {
            
            InitializeComponent();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if(MessageBox.Show("Do you want to close",
                                "Warning",    
                                MessageBoxButtons.YesNo,
                                MessageBoxIcon.Question
                               ) ==  
                    System.Windows.Forms.DialogResult.Yes)   
                       Application.Exit();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            AddHotelDialog dlg = new AddHotelDialog();
            dlg.ShowDialog();
 
            if (dlg.HotelName != "")
            {
                label1.Text = dlg.City.ToString(); 
                label2.Text = dlg.HotelName.ToString(); 
                label3.Text = dlg.Rooms.ToString(); 
                label4.Text = dlg.Rate.ToString(); 
            } else { 
                MessageBox.Show("Введите данные",
                                "Hotel Broker Administration",
                                MessageBoxButtons.OK,  
                                MessageBoxIcon.Exclamation
                                );
            }
                Hotel ob = new Hotel(dlg.City, dlg.HotelName, Int32.Parse(dlg.Rooms), Int32.Parse(dlg.Rate));
  list.Add(ob);
                String s=dlg.City+"," +dlg.HotelName+","+dlg.Rooms.ToString()+"," +dlg.Rate.ToString(); 
  hotellist.Items.Add(s); 
   
              
        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            button1_Click(sender, e);
        }

        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            
              Hotel ob1=new  Hotel("Москва","Россия",200,1500); 
            list.Add(ob1); 
   Hotel ob2=new Hotel("Москва","Прага",200,3000); 
   list.Add(ob2); 
   Hotel ob3=new Hotel("Новосибирск","Объ",150,1500); 
   list.Add(ob3); 
   Hotel ob4=new Hotel("Новосибирск","Тратата",300,1200); 
   list.Add(ob4); 
              hotellist.Items.Clear();  
   if (list == null) { return; }  
   foreach(Hotel hotel in list) {  
                 // строка для записи в элемент ListBox  hotellist   
             String city = hotel.City.Trim();  
             String name = hotel.HotelName.Trim();  
             String rooms = hotel.Rooms.ToString();  
             String rate = hotel.Rate.ToString();  
             String str = city + "," + name + "," + rooms + "," + rate;
        hotellist.Items.Add(str); 
        }  
      }

        private void hotellist_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (hotellist.SelectedIndex != -1)
            {
                String selected = hotellist.SelectedItem.ToString();
                String[] fields;
                fields = selected.Split(','); // поля разбить;  
                label1.Text = fields[0];
                label2.Text = fields[1];
                label3.Text = fields[2];
                label4.Text = fields[3];
            }
            else { label1.Text = ""; }
        }
        }
    }

